<?php

namespace app\controllers;

use app\libs\Method;
use Yii;

use yii\web\Controller;


class ImportController extends Controller
{

    public $enableCsrfValidation = false;
    public function actionIndex()
    {
        var_dump(111);die;

//        var_dump($_GET);die;
//        $userId = Yii::$app->session->get('userId');
//        if(!$userId){
//            $this->redirect('/user/login/index');
//        }else{
            return $this->renderPartial('index');
//        }
    }

    /**
     * 文件上传
     */
    public function actionUploadFile()
    {
        $file = $_FILES['file'];
        if(!$file){
            die(Method::jsonGenerate(0,'','请选择文件'));
        }
        $upload = new \UploadFile();
        $upload->int_max_size = 52428800;//50MB
        $upload->str_save_path = Yii::$app->params['upImage'].date('Ym').'/';
        $arr_rs = $upload->upload($file);
        if ($arr_rs['int_code'] == 1) {
            $arr = $arr_rs['arr_data']['arr_data'][0];
            $name = !empty($file['name'])?$file['name']:$arr['savename'];
            $filePath = '/' . $arr['savepath'] . $arr['savename'];
            $res['code'] = 1;
            $res['message'] = '上传成功';
            $res['path'] = $filePath;
            $res['name'] = $name;
        } else {
            $res['code'] = 0;
            if($arr_rs['arr_data']['int_error']==8) {
                $res['message'] = '上传失败，文件大小超出限制';
            }else{
                $res['message'] = '上传失败，请重试';
            }
        }
        die(json_encode($res));
    }

}
